package com.biglead.orderservice.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.biglead.common.pojo.UserInfo;
import com.biglead.feign.clients.FeignUserClient;
import com.biglead.orderservice.mapper.OrderMapper;
import com.biglead.orderservice.pojo.OrderInfo;
import com.biglead.orderservice.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
@Slf4j
public class OrderServiceImpl extends ServiceImpl<OrderMapper, OrderInfo> implements OrderService {

    @Resource
    private FeignUserClient feignUserClient;
    /**
     * 查询订单详情
     *
     * @param id
     */
    @Override
    public OrderInfo queryById(Long id) {
        OrderInfo orderInfo = this.getById(id);
        if (orderInfo==null) {
            throw  new RuntimeException("未查询到订单");
        }
        Long userId = orderInfo.getUserId();
        //根据用户ID来查询用户信息
        UserInfo userInfo = feignUserClient.queryById(userId);
        orderInfo.setUserInfo(userInfo);
        return orderInfo;
    }
}
